var t = getApp();

Page({
    data: {
        img: "",
        text: "",
        _num: 1,
        dates: "",
        times: "",
        dates1: "",
        times1: "",
        textInput: "",
        textInput1: "",
        textInput2: ""
    },
    textInput: function(t) {
        console.log(t.detail.value);
        var e = t.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
        this.setData({
            textInput: e
        });
    },
    textInput1: function(t) {
        console.log(t.detail.value);
        var e = t.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
        this.setData({
            textInput1: e
        });
    },
    textInput2: function(t) {
        console.log(t.detail.value);
        var e = t.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
        this.setData({
            textInput2: e
        });
    },
    menuClick: function(t) {
        console.log(t.target.dataset.num), this.setData({
            _num: t.target.dataset.num
        });
    },
    bindTimeChange: function(t) {
        console.log(t.detail.value), this.setData({
            times: t.detail.value
        });
    },
    bindDateChange: function(t) {
        console.log(t.detail.value), this.setData({
            dates: t.detail.value
        });
    },
    bindTimeChange1: function(t) {
        console.log(t.detail.value), this.setData({
            times1: t.detail.value
        });
    },
    bindDateChange1: function(t) {
        console.log(t.detail.value), this.setData({
            dates1: t.detail.value
        });
    },
    bindTimeChanges: function(t) {
        console.log(t.detail.value), this.setData({
            timess: t.detail.value
        });
    },
    bindDateChanges: function(t) {
        console.log(t.detail.value), this.setData({
            datess: t.detail.value
        });
    },
    bindTimeChange1s: function(t) {
        console.log(t.detail.value), this.setData({
            times1s: t.detail.value
        });
    },
    bindDateChange1s: function(t) {
        console.log(t.detail.value), this.setData({
            dates1s: t.detail.value
        });
    },
    onLoad: function(e) {
        var a = this;
        a.click(), a.click1(), 1 == (wx.getStorageSync("WapprovePrice2") || "") && a.setData({
            img: "/assets/images/pho.png",
            text: "图文咨询"
        }), wx.request({
            url: t.globalData.dicc + "dic/comdicbase",
            data: {
                code: 29e4
            },
            success: function(t) {}
        }), a.onClick();
    },
    click: function(t) {
        var e = this, a = Date.parse(new Date()), n = 1e3 * (a /= 1e3), s = new Date(n), o = s.getFullYear(), i = s.getMonth() + 1 < 10 ? "0" + (s.getMonth() + 1) : s.getMonth() + 1, d = s.getDate() < 10 ? "0" + s.getDate() : s.getDate(), l = s.getHours() < 10 ? "0" + s.getHours() : s.getHours(), c = s.getMinutes() < 10 ? "0" + s.getMinutes() : s.getMinutes(), r = (s.getSeconds() < 10 ? s.getSeconds() : s.getSeconds(), 
        o + "-" + i + "-" + d), u = l + ":" + c;
        e.setData({
            dates: r,
            times: u,
            datess: r,
            timess: u
        });
    },
    click1: function(t) {
        var e = this, a = Date.parse(new Date()) + 31536e6, n = 1e3 * (a /= 1e3), s = new Date(n), o = s.getFullYear(), i = s.getMonth() + 1 < 10 ? "0" + (s.getMonth() + 1) : s.getMonth() + 1, d = s.getDate() < 10 ? "0" + s.getDate() : s.getDate(), l = s.getHours() < 10 ? "0" + s.getHours() : s.getHours(), c = s.getMinutes() < 10 ? "0" + s.getMinutes() : s.getMinutes(), r = (s.getSeconds() < 10 ? s.getSeconds() : s.getSeconds(), 
        o + "-" + i + "-" + d), u = l + ":" + c;
        e.setData({
            dates1: r,
            times1: u,
            dates1s: r,
            times1s: u
        });
    },
    onClick: function(e) {
        var a = wx.getStorageSync("log") || "", n = this;
        wx.request({
            url: t.globalData.dic + "doctor/service/listServiceItem/" + a,
            success: function(t) {
                if (console.log(t.data.data), t.data.data.length > 0) {
                    if (n.setData({
                        arr: t.data.data,
                        textInput: t.data.data[0].servicePrice / 100
                    }), null != t.data.data[0].signProm) {
                        var e = t.data.data[0].signProm.beginDate.substring(0, 10), a = t.data.data[0].signProm.beginDate.substring(11, 16), s = t.data.data[0].signProm.endDate.substring(0, 10), o = t.data.data[0].signProm.endDate.substring(11, 16);
                        n.setData({
                            dates: e,
                            times: a,
                            dates1: s,
                            times1: o,
                            textInput1: t.data.data[0].signProm.money / 100
                        });
                    }
                    if (null != t.data.data[0].quickProm) {
                        var i = t.data.data[0].quickProm.beginDate.substring(0, 10), d = t.data.data[0].quickProm.beginDate.substring(11, 16), l = t.data.data[0].quickProm.endDate.substring(0, 10), c = t.data.data[0].quickProm.endDate.substring(11, 16);
                        n.setData({
                            datess: i,
                            timess: d,
                            dates1s: l,
                            times1s: c,
                            textInput2: t.data.data[0].quickProm.money / 100
                        });
                    }
                }
            }
        });
    },
    foot: function(e) {
        var a = wx.getStorageSync("log") || "", n = this;
        wx.showLoading({
            title: "加载中",
            mask: "true"
        }), console.log(n.data.dates + " " + n.data.times);
        var s = n.data.dates + " " + n.data.times;
        s = s.replace(/-/g, "/");
        var o = Date.parse(new Date(s));
        o /= 1e3, console.log(o);
        var i = n.data.dates1 + " " + n.data.times1;
        i = i.replace(/-/g, "/");
        var d = Date.parse(new Date(i));
        d /= 1e3, console.log(d);
        var l = n.data.datess + " " + n.data.timess;
        l = l.replace(/-/g, "/");
        var c = Date.parse(new Date(l));
        c /= 1e3, console.log(c);
        var r = n.data.dates1s + " " + n.data.times1s;
        r = r.replace(/-/g, "/");
        var u = Date.parse(new Date(r));
        u /= 1e3, console.log(u);
        var g = parseFloat(n.data.textInput), m = parseFloat(n.data.textInput1), p = parseFloat(n.data.textInput2), D = {
            cdInterroga: "290101",
            nmInterroga: "图文咨询",
            servicePrice: 100 * n.data.textInput,
            signProm: {
                money: 100 * n.data.textInput1,
                beginDate: n.data.dates + " " + n.data.times + ":00",
                endDate: n.data.dates1 + " " + n.data.times1 + ":00"
            },
            quickProm: {
                money: 100 * n.data.textInput2,
                beginDate: n.data.datess + " " + n.data.timess + ":00",
                endDate: n.data.dates1s + " " + n.data.times1s + ":00"
            }
        }, v = {
            cdInterroga: "290101",
            nmInterroga: "图文咨询",
            servicePrice: 100 * n.data.textInput,
            signProm: {
                money: 100 * n.data.textInput1,
                beginDate: n.data.dates + " " + n.data.times + ":00",
                endDate: n.data.dates1 + " " + n.data.times1 + ":00"
            },
            quickProm: {}
        }, x = {
            cdInterroga: "290101",
            nmInterroga: "图文咨询",
            servicePrice: 100 * n.data.textInput,
            signProm: {},
            quickProm: {
                money: 100 * n.data.textInput2,
                beginDate: n.data.datess + " " + n.data.timess + ":00",
                endDate: n.data.dates1s + " " + n.data.times1s + ":00"
            }
        }, h = {
            cdInterroga: "290101",
            nmInterroga: "图文咨询",
            servicePrice: 100 * n.data.textInput,
            signProm: {},
            quickProm: {}
        }, D = JSON.stringify(D), v = JSON.stringify(v), x = JSON.stringify(x), h = JSON.stringify(h);
        console.log(g), console.log(m), console.log(p), n.setData({
            textInput2: ""
        }), g < 0 ? wx.showToast({
            title: "请填写价格",
            icon: "none",
            duration: 2e3
        }) : "" == n.data.textInput1 && "" == n.data.textInput2 ? wx.request({
            url: t.globalData.dic + "doctor/service/addServiceItem/" + a,
            method: "POST",
            header: {
                "Content-Type": "application/json"
            },
            data: h,
            success: function(t) {
                console.log(t.data.data), wx.navigateBack({
                    delta: 1
                });
            }
        }) : "" == n.data.textInput1 && "" != n.data.textInput2 ? g >= p ? c < u ? wx.request({
            url: t.globalData.dic + "doctor/service/addServiceItem/" + a,
            method: "POST",
            header: {
                "Content-Type": "application/json"
            },
            data: x,
            success: function(t) {
                console.log(t.data.data), wx.navigateBack({
                    delta: 1
                });
            }
        }) : wx.showToast({
            title: "优惠结束时间要大于开始时间",
            icon: "none",
            duration: 2e3
        }) : wx.showToast({
            title: "服务价格不能小于优惠价格",
            icon: "none",
            duration: 2e3
        }) : "" == n.data.textInput2 && "" != n.data.textInput1 ? g >= m ? o < d ? wx.request({
            url: t.globalData.dic + "doctor/service/addServiceItem/" + a,
            method: "POST",
            header: {
                "Content-Type": "application/json"
            },
            data: v,
            success: function(t) {
                console.log(t.data.data), wx.navigateBack({
                    delta: 1
                });
            }
        }) : wx.showToast({
            title: "优惠结束时间要大于开始时间",
            icon: "none",
            duration: 2e3
        }) : wx.showToast({
            title: "服务价格不能小于优惠价格",
            icon: "none",
            duration: 2e3
        }) : "" != n.data.textInput1 && "" != n.data.textInput2 && (g >= m && g >= p ? o < d && c < u ? wx.request({
            url: t.globalData.dic + "doctor/service/addServiceItem/" + a,
            method: "POST",
            header: {
                "Content-Type": "application/json"
            },
            data: D,
            success: function(t) {
                wx.navigateBack({
                    delta: 1
                });
            }
        }) : wx.showToast({
            title: "优惠结束时间要大于开始时间",
            icon: "none",
            duration: 2e3
        }) : wx.showToast({
            title: "服务价格不能小于优惠价格",
            icon: "none",
            duration: 2e3
        }));
    }
});